package com.example.springbootredis.mapper;
;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.eshop.entity.Cart;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CartMapper extends BaseMapper<Cart> {

    @Select("SELECT c.*, p.name as product_name, p.price as product_price, " +
            "p.main_image, p.status as product_status, p.stock as product_stock " +
            "FROM cart c LEFT JOIN product p ON c.product_id = p.id " +
            "WHERE c.user_id = #{userId} ORDER BY c.create_time DESC")
    List<Cart> selectCartWithProduct(@Param("userId") Long userId);
}